from flask import Flask
from flask import render_template
from flask import jsonify
from mysql import Mysql
from flask_cors import CORS

app = Flask(__name__)

CORS(app)


@app.route('/')
def index():
    return render_template('index.html')


@app.route('/left1', methods=['GET', 'POST'])
def getdata1():
    db = Mysql()
    items = db.ys_t()
    return jsonify(items)

@app.route('/left2', methods=['GET', 'POST'])
def getdata2():
    db = Mysql()
    items = db.xmsj_t()
    return jsonify(items)

@app.route('/left3', methods=['GET', 'POST'])
def getdata3():
    db = Mysql()
    data = db.kmys_t()
    items = [{'name': row[0], 'value': float(row[1])} for row in data]
    return jsonify(items)

@app.route('/right1', methods=['GET', 'POST'])
def getdata4():
    db = Mysql()
    items = db.lnsj_t()
    return jsonify(items)


@app.route('/right2', methods=['GET', 'POST'])
def getdata5():
    db = Mysql()
    items = db.gysj_t()
    return jsonify(items)


@app.route('/right3', methods=['GET', 'POST'])
def getdata6():
    db = Mysql()
    items = db.xjlpm_t()
    return jsonify(items)



if __name__ == '__main__':
    app.run(host='0.0.0.0', port=5000)
